package bar.dark.lee.select;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import bar.dark.lee.BDConstents;
import bar.dark.lee.R;
import bar.dark.lee.SuperActivity;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.common.CalendarPickerDialog;
import bar.dark.lee.common.DBSQLite;
import bar.dark.lee.common.KeyValueAdapter;
import bar.dark.lee.common.DBSQLite.ParseSelectData;
import bar.dark.lee.common.EditTextInputFilter;
import bar.dark.lee.common.RadioDialogActivity;
import bar.dark.lee.insert.BalanceQuery;
import bar.dark.lee.setting.category.CategoryData;

public class SelectUpdateActivity extends SuperActivity
{
	private static final int REQUEST_CATEGORY = 0;
	private static final int REQUEST_NAME = 1;
	private static final int REQUEST_KIND = 2;
	private static final int REQUEST_TYPE = 3;
	
	private String[] fixCategory = new String[]{
			BDConstents.CATEGORY_SUSUMONEY,
			BDConstents.CATEGORY_FAN_OUT_MONEY,
			BDConstents.CATEGORY_FAN_IN_MONEY,
			BDConstents.CATEGORY_FAN_OUT_CHECK,
			BDConstents.CATEGORY_FAN_IN_CHECK,
			BDConstents.CATEGORY_POST_OUT,
			BDConstents.CATEGORY_USE_CARD,
			BDConstents.CATEGORY_IN_CARD,
			BDConstents.CATEGORY_OUT_CARD,
			BDConstents.CATEGORY_OUT_BANK,
			BDConstents.CATEGORY_IN_BANK
		};
	
	private DBSQLite sql;
	
	private Button updateButton;
	
	private SelectData data;
	
	private TextView typeTextView; // 타입 텍스트뷰
	private View typeView; // 타입 뷰
	private ImageView typeImage; // 타입 이미지
	
	private View kindView; // 종류 전체뷰
	private TextView kindTextView; // 종류 텍스트뷰
	private ImageView kindImage; // 종류 이미지
	
	private TextView categoryTextView; // 카테고리 텍스트뷰
	private View categoryView; // 카테고리 뷰
	private ImageView categoryImage;
	
	private View nameView; // 이름 뷰
	private TextView nameTextView; // 이름 텍스트뷰
	private ImageView nameImage; // 이름 스피너
	
	private View dateView; // 날짜 뷰
	private TextView dateTextView; // 날짜 텍스트 뷰
	private ImageView dateImage; // 날짜 이미지
	
	private View moneyRadioView; // 라디오 전체뷰
	private RadioButton inMoneyRadio; // 지출라디오 버튼
	private RadioButton outMoneyRadio; // 수입라디오 버튼
	
	private View inMoneyView; // 수입 전체뷰
	private EditText inMoneyEditText; // 수입 에디트
	
	private View outMoneyView; // 지출 전체뷰
	private EditText outMoneyEditText; // 지출 에디트
	
	private View postMoneyView; // // 카드대금 전체뷰
	private EditText postMoneyEditText; // 카드대금 에디트
	
	private View cashView; // 현금인출 전체뷰
	private EditText cashEditText; // 현금인출 에디트
	
	private EditText memoEditText; // 내용 에디트
	
//	private View subBalanceView; // 잔액 뷰
//	private TextView subBalanceTitleTextView; // 잔액 제목 텍스트
//	private EditText subBalanceEditText; // 잔액 에디트
//	
//	private View realBalanceView; // 현금잔액 뷰
//	private EditText realBalanceEditText; // 현금잔액 에디트
	
	private TextView creditTitle;
	private TextView outTitle;
	private TextView cashTitle;
	
	private ArrayList<String> categoryList;
	private ArrayList<String> nameList;
	
	private ArrayList<String> types;
	
	private int toYear;
	private int toMonth;
	private int toDay;
	
	private String lastQuery = "";
	private String firstQuery = "";
	
	private String name = "";
	
	private SelectData tempData;
	
	private int categoryInOutFlag;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		super.setGoneTipButton();
		
		sql = DBSQLite.getInstance(this);
		
		setTitle("내역 수정");
		
		setContentView(R.layout.select_update_activity);
		setFindView();
		setClickListener();
		setData();
	}

	private void setFindView()
	{
		typeView = findViewById(R.id.selectUpdateTypeView);
		typeTextView = (TextView) findViewById(R.id.selectUpdateTypeTextView);
		typeImage = (ImageView) findViewById(R.id.selectUpdateTypeImageView);
		
		kindView = findViewById(R.id.selectUpdateKindView);
		kindTextView = (TextView) findViewById(R.id.selectUpdateKindTextView);
		kindImage = (ImageView) findViewById(R.id.selectUpdateKindImageView);
		
		categoryTextView = (TextView) findViewById(R.id.selectUpdateCategoryTextView);
		categoryView = findViewById(R.id.selectUpdateCategoryView);
		categoryImage = (ImageView) findViewById(R.id.selectUpdateCategoryImage);
		
		nameView = findViewById(R.id.selectUpdateNameView);
		nameTextView = (TextView) findViewById(R.id.selectUpdateNameTextView);
		nameImage = (ImageView) findViewById(R.id.selectUpdateNameImage);
		
		dateView = findViewById(R.id.selectUpdateDateView);
		dateTextView = (TextView) findViewById(R.id.selectUpdateDateTextView);
		dateImage = (ImageView) findViewById(R.id.selectUpdateDateImage);
		
		moneyRadioView = findViewById(R.id.selectUpdateMoneyRadioView);
		inMoneyRadio = (RadioButton) findViewById(R.id.selectUpdateRadioInMoney);
		outMoneyRadio = (RadioButton) findViewById(R.id.selectUpdateRadioOutMoney);
		
		inMoneyView = findViewById(R.id.selectUpdateInMoneyView);
		inMoneyEditText = (EditText) findViewById(R.id.selectUpdateInMoneyEditText);
		EditTextInputFilter.filteringMoneyEditText(inMoneyEditText);
		
		outMoneyView = findViewById(R.id.selectUpdateOutMoneyView);
		outMoneyEditText = (EditText) findViewById(R.id.selectUpdateOutMoneyEditText);
		EditTextInputFilter.filteringMoneyEditText(outMoneyEditText);
		
		postMoneyView = findViewById(R.id.selectUpdatePostMoneyView);
		postMoneyEditText = (EditText) findViewById(R.id.selectUpdatePostMoneyEdit);
		EditTextInputFilter.filteringMoneyEditText(postMoneyEditText);
		
		cashView = findViewById(R.id.selectUpdateCashView);
		cashEditText = (EditText) findViewById(R.id.selectUpdateCashEdit);
		EditTextInputFilter.filteringMoneyEditText(cashEditText);
		
		memoEditText = (EditText) findViewById(R.id.selectUpdateMemoEditText);
		
		creditTitle = (TextView) findViewById(R.id.selectUpdateCreditTitle);
		outTitle = (TextView) findViewById(R.id.selectUpdateOutTitle);
		cashTitle = (TextView) findViewById(R.id.selectUpdateCashTitle);
		
		updateButton = (Button) findViewById(R.id.selectUpdateButton);
	}

	private void setData()
	{
		types = new ArrayList<String>();
		types.add(BDConstents.REAL_MONEY);
		types.add(BDConstents.BANK_MONEY);
		
		Intent intent = getIntent();
		data = intent.getParcelableExtra(SelectActivity.SELECT_DATA);
		
		categoryTextView.setText(data.getCategory());
		
		if (data.getType().equals(BDConstents.INOUT_TYPE))
		{
			types.clear();
			types = new ArrayList<String>();
			types.add(BDConstents.BANK_MONEY);
			types.add(BDConstents.CHECK_CARD);
			types.add(BDConstents.CREDIT_CARD);
			
			typeTextView.setText(BDConstents.BANK_TO_REAL);
			typeImage.setVisibility(View.INVISIBLE);
			typeView.setClickable(false);
			kindView.setVisibility(View.VISIBLE);
			moneyRadioView.setVisibility(View.GONE);
			categoryView.setClickable(true);
			inMoneyView.setVisibility(View.GONE);
			outMoneyView.setVisibility(View.GONE);
			
			// 종류데이터를 셋팅한다.
			if (data.getLinktype().equals(BDConstents.BANK_TYPE))
			{
				kindTextView.setText(BDConstents.BANK_MONEY);
				postMoneyView.setVisibility(View.GONE);
			}
			else if (data.getLinktype().equals(BDConstents.CHECK_TYPE))
			{
				kindTextView.setText(BDConstents.CHECK_CARD);
				postMoneyView.setVisibility(View.GONE);
			}
			else if (data.getLinktype().equals(BDConstents.CREDIT_TYPE))
			{
				kindTextView.setText(BDConstents.CREDIT_CARD);
				cashView.setVisibility(View.GONE);
			}
			
			categoryImage.setVisibility(View.VISIBLE);
			categoryTextView.setVisibility(View.VISIBLE);
			
			setCategorySpinner();
			setKindData();
			
			if (data.getCategory().equals(BDConstents.CATEGORY_SUSUMONEY))
			{
				inMoneyView.setVisibility(View.GONE);
				cashView.setVisibility(View.GONE);
				kindImage.setVisibility(View.INVISIBLE);
				kindView.setClickable(false);
				categoryImage.setVisibility(View.INVISIBLE);
				categoryView.setClickable(false);
				dateImage.setVisibility(View.INVISIBLE);
				dateView.setClickable(false);
				
				if (data.getLinktype().equals(BDConstents.CREDIT_TYPE))
				{
					postMoneyView.setVisibility(View.VISIBLE);
				}
				else
				{
					outMoneyView.setVisibility(View.VISIBLE);
				}
			}
		}
		else if (data.getType().equals(BDConstents.OUTIN_TYPE))
		{
			types.clear();
			types = new ArrayList<String>();
			types.add(BDConstents.BANK_MONEY);
			types.add(BDConstents.CHECK_CARD);
			
			cashTitle.setText("현금입금");
			typeTextView.setText(BDConstents.REAL_TO_BANK);
			typeImage.setVisibility(View.INVISIBLE);
			typeView.setClickable(false);
			kindView.setVisibility(View.VISIBLE);
			moneyRadioView.setVisibility(View.GONE);
			categoryView.setClickable(true);
			inMoneyView.setVisibility(View.GONE);
			outMoneyView.setVisibility(View.GONE);
			
			// 종류데이터를 셋팅한다.
			if (data.getLinktype().equals(BDConstents.BANK_TYPE))
			{
				kindTextView.setText(BDConstents.BANK_MONEY);
				postMoneyView.setVisibility(View.GONE);
			}
			else if (data.getLinktype().equals(BDConstents.CHECK_TYPE))
			{
				kindTextView.setText(BDConstents.CHECK_CARD);
				postMoneyView.setVisibility(View.GONE);
			}
			
			categoryImage.setVisibility(View.VISIBLE);
			categoryTextView.setVisibility(View.VISIBLE);
			
			setCategorySpinner();
			setKindData();
		}
		else if (data.getCategory().equals(BDConstents.CATEGORY_POST_OUT)) 
		{
			typeImage.setVisibility(View.INVISIBLE);
			typeView.setClickable(false);
			categoryImage.setVisibility(View.INVISIBLE);
			postMoneyView.setVisibility(View.GONE);
			cashView.setVisibility(View.GONE);
			moneyRadioView.setVisibility(View.GONE);
			kindView.setVisibility(View.GONE);
			inMoneyView.setVisibility(View.GONE);
			
			if (data.getType().equals(BDConstents.REAL_TYPE))
			{
				typeTextView.setText(BDConstents.REAL_MONEY);
			}
			else if (data.getType().equals(BDConstents.BANK_TYPE))
			{
				typeTextView.setText(BDConstents.BANK_MONEY);
			}
			else if (data.getType().equals(BDConstents.CHECK_TYPE))
			{
				typeTextView.setText(BDConstents.CHECK_CARD);
			}
			else if (data.getType().equals(BDConstents.CREDIT_TYPE))
			{
				typeTextView.setText(BDConstents.CREDIT_CARD);
				postMoneyView.setVisibility(View.VISIBLE);
				inMoneyView.setVisibility(View.GONE);
				outMoneyView.setVisibility(View.GONE);
			}
		}
		else if (data.getType().equals(BDConstents.MYBANK_INOUT_TYPE))
		{
			typeImage.setVisibility(View.INVISIBLE);
			typeView.setClickable(false);
			typeTextView.setText(BDConstents.MYBANK_INOUT);
			cashView.setVisibility(View.GONE);
			moneyRadioView.setVisibility(View.GONE);
			categoryView.setClickable(true);
			nameImage.setVisibility(View.INVISIBLE);
			kindView.setVisibility(View.VISIBLE);
			kindImage.setVisibility(View.INVISIBLE);
			kindView.setClickable(false);
			dateImage.setVisibility(View.INVISIBLE);
			dateView.setClickable(false);
			
			if (data.getLinktype().equals(BDConstents.BANK_TYPE))
			{
				if (data.getInMoney().equals("0"))
				{
					inMoneyView.setVisibility(View.GONE);
					outMoneyView.setVisibility(View.VISIBLE);
					
					types.add(BDConstents.CHECK_CARD);
					types.add(BDConstents.CREDIT_CARD);
				}
				else
				{
					inMoneyView.setVisibility(View.VISIBLE);
					outMoneyView.setVisibility(View.GONE);
				}
				
				kindTextView.setText(BDConstents.BANK_MONEY);
				postMoneyView.setVisibility(View.GONE);
			}
			else if (data.getLinktype().equals(BDConstents.CHECK_TYPE))
			{
				if (data.getInMoney().equals("0"))
				{
					inMoneyView.setVisibility(View.GONE);
					outMoneyView.setVisibility(View.VISIBLE);
					
					types.add(BDConstents.CHECK_CARD);
					types.add(BDConstents.CREDIT_CARD);
				}
				else
				{
					inMoneyView.setVisibility(View.VISIBLE);
					outMoneyView.setVisibility(View.GONE);
				}
				
				kindTextView.setText(BDConstents.CHECK_CARD);
				postMoneyView.setVisibility(View.GONE);
			}
			else if (data.getLinktype().equals(BDConstents.CREDIT_TYPE))
			{
				inMoneyView.setVisibility(View.GONE);
				outMoneyView.setVisibility(View.GONE);
				postMoneyView.setVisibility(View.VISIBLE);
				
				types.add(BDConstents.CHECK_CARD);
				types.add(BDConstents.CREDIT_CARD);
				
				kindTextView.setText(BDConstents.CREDIT_CARD);
			}
			
			setCategorySpinner();
			
			if (data.getCategory().equals(BDConstents.CATEGORY_SUSUMONEY))
			{
				kindImage.setVisibility(View.INVISIBLE);
				kindView.setClickable(false);
				categoryImage.setVisibility(View.INVISIBLE);
				categoryView.setClickable(false);
				dateImage.setVisibility(View.INVISIBLE);
				dateView.setClickable(false);
//				categoryTextView.setGravity(Gravity.RIGHT);
			}
		}
		else
		{
			moneyRadioView.setVisibility(View.GONE);
			postMoneyView.setVisibility(View.GONE);
			cashView.setVisibility(View.GONE);
			kindView.setVisibility(View.GONE);
			
			if (data.getInMoney().equals("0"))
			{
				inMoneyView.setVisibility(View.GONE);
				outMoneyView.setVisibility(View.VISIBLE);
				
				types.add(BDConstents.CHECK_CARD);
				types.add(BDConstents.CREDIT_CARD);
			}
			else
			{
				inMoneyView.setVisibility(View.VISIBLE);
				outMoneyView.setVisibility(View.GONE);
			}
			
			if (data.getType().equals(BDConstents.REAL_TYPE))
			{
				typeTextView.setText(BDConstents.REAL_MONEY);
			}
			else if (data.getType().equals(BDConstents.BANK_TYPE))
			{
				typeTextView.setText(BDConstents.BANK_MONEY);
			}
			else if (data.getType().equals(BDConstents.CHECK_TYPE))
			{
				typeTextView.setText(BDConstents.CHECK_CARD);
			}
			else if (data.getType().equals(BDConstents.CREDIT_TYPE))
			{
				typeTextView.setText(BDConstents.CREDIT_CARD);
				postMoneyView.setVisibility(View.VISIBLE);
				inMoneyView.setVisibility(View.GONE);
				outMoneyView.setVisibility(View.GONE);
			}
			
			setCategorySpinner();
			setTypeData();
		}
		
		setName(data.getType());
		
		dateTextView.setText(BDUtil.getDateButton(data.getDate()));
		
		int [] dateSet = BDUtil.getDateSet(data.getDate());
		toYear = dateSet[0];
		toMonth = dateSet[1]-1;
		toDay = dateSet[2];
		
		inMoneyEditText.setText(data.getInMoney());
		outMoneyEditText.setText(data.getOutMoney());
		postMoneyEditText.setText(data.getPostMoney());
		cashEditText.setText(data.getOutMoney());
		memoEditText.setText(data.getMemo());
	}

	private void setRadioButtonEn()
	{
		if (!data.getInMoney().equals("0"))
		{
			setCheckInMoneyRadioButton(true);
		}
		else if (!data.getOutMoney().equals("0"))
		{
			setCheckOutMoneyRadioButton(true);
		}
	}

	/**
	 * 카테고리 데이터를 삽입한다.
	 */
	private void setCategorySpinner()
	{
		categoryImage.setVisibility(View.VISIBLE);
		categoryTextView.setVisibility(View.VISIBLE);
		
		if (data.getType().equals(BDConstents.INOUT_TYPE)
				|| data.getType().equals(BDConstents.OUTIN_TYPE)
				|| data.getType().equals(BDConstents.MYBANK_INOUT_TYPE))
		{
			setCategoryData("category_move_list");
		}
		else
		{
			if (inMoneyView.getVisibility() == View.VISIBLE)
			{
				setCategoryData("category_in_list");
			}
			else
			{
				setCategoryData("category_out_list");
			}
		}
		
	}

	/**
	 * 카테고리 목록을 가져온다.
	 */
	private void setCategoryData(final String tableName)
	{
		if (tableName.equals("category_in_list"))
		{
			categoryInOutFlag = 0;
		}
		else if(tableName.equals("category_out_list"))
		{
			categoryInOutFlag = 1;
		}
		else
		{
			categoryInOutFlag = 2;
		}
		
		sql.selectMapTile(this, "SELECT kind FROM " + tableName + " ORDER BY count DESC;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				categoryList = new ArrayList<String>();
				
				int kindIndex = c.getColumnIndex("kind");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					String kind = "";
					kind = c.getString(kindIndex);
					categoryList.add(kind);
					
					c.moveToNext();
				}
				
				if (tableName.equals("category_in_list"))
				{
				}
				else if(tableName.equals("category_out_list"))
				{
					categoryList.add(BDConstents.CATEGORY_USE_CARD);
				}
				else
				{
					if (data.getType().equals(BDConstents.INOUT_TYPE))
					{
						categoryList.add(BDConstents.CATEGORY_OUT_CARD);
						categoryList.add(BDConstents.CATEGORY_OUT_BANK);
					}
					else
					{
						categoryList.add(BDConstents.CATEGORY_IN_CARD);
						categoryList.add(BDConstents.CATEGORY_IN_BANK);
					}
				}
				
				if (categoryList.size() < 1)
				{
					String memo = "없음";
					categoryList.add(memo);
					categoryView.setClickable(false);
				}
				else
				{
					categoryView.setOnClickListener(new OnClickListener()
					{
						@Override
						public void onClick(View v)
						{
							Intent intent = new Intent(SelectUpdateActivity.this, RadioDialogActivity.class);
							intent.putExtra(RadioDialogActivity.RADIODATA, categoryList);
							intent.putExtra(RadioDialogActivity.RADIOSELECT, categoryTextView.getText().toString());
							startActivityForResult(intent, REQUEST_CATEGORY);
						}
					});
				}
			}
		});
	}
	
	private void setTypeData()
	{
		typeView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(SelectUpdateActivity.this, RadioDialogActivity.class);
				intent.putExtra(RadioDialogActivity.RADIODATA, types);
				intent.putExtra(RadioDialogActivity.RADIOSELECT, typeTextView.getText().toString());
				startActivityForResult(intent, REQUEST_TYPE);
			}
		});
	}
	
	private void setKindData()
	{
		kindView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(SelectUpdateActivity.this, RadioDialogActivity.class);
				intent.putExtra(RadioDialogActivity.RADIODATA, types);
				intent.putExtra(RadioDialogActivity.RADIOSELECT, kindTextView.getText().toString());
				startActivityForResult(intent, REQUEST_KIND);
			}
		});
	}
	
	/**
	 * 이름을 데이터 목록을 가져와서 셋팅한다.
	 * @param type
	 */
	private void setName(String type)
	{
		nameView.setVisibility(View.VISIBLE);
		nameImage.setVisibility(View.VISIBLE);
		
		if (type.equals(BDConstents.REAL_TYPE))
		{
			nameView.setVisibility(View.GONE);
			nameImage.setVisibility(View.GONE);
			nameView.setClickable(false);
			
			outTitle.setText("지출");
			creditTitle.setText("지출");
		}
		else if (type.equals(BDConstents.BANK_TYPE))
		{
			setNameData("bankbook");
			outTitle.setText("지출");
			creditTitle.setText("지출");
		}
		else if (type.equals(BDConstents.CHECK_TYPE))
		{
			setNameData("check_card");
			outTitle.setText("지출");
			creditTitle.setText("지출");
		}
		else if (type.equals(BDConstents.CREDIT_TYPE))
		{
			setNameData("credit_card");
			outTitle.setText("카드대금");
			creditTitle.setText("카드대금");
		}
		else if (type.equals(BDConstents.INOUT_TYPE))
		{
			if (data.getCategory().equals(BDConstents.CATEGORY_SUSUMONEY))
			{
				nameImage.setVisibility(View.INVISIBLE);
				nameView.setClickable(false);
			}
			else
			{
				if (data.getLinktype().equals(BDConstents.BANK_TYPE))
				{
					setNameData("bankbook");
				}
				else if (data.getLinktype().equals(BDConstents.CHECK_TYPE))
				{
					setNameData("check_card");
				}
				else if (data.getLinktype().equals(BDConstents.CREDIT_TYPE))
				{
					setNameData("credit_card");
				}
			}
		}
		else if (type.equals(BDConstents.OUTIN_TYPE))
		{
			if (data.getLinktype().equals(BDConstents.BANK_TYPE))
			{
				setNameData("bankbook");
			}
			else if (data.getLinktype().equals(BDConstents.CHECK_TYPE))
			{
				setNameData("check_card");
			}
		}
		else if (type.equals(BDConstents.MYBANK_INOUT_TYPE))
		{
			nameView.setClickable(false);
			nameImage.setVisibility(View.INVISIBLE);
		}
		
		if (data.getType().equals(type))
		{
			nameTextView.setText(data.getMoneyKind());
		}
	}

	/**
	 * 이름에 들어갈 데이터를 가져온다.
	 * @param string
	 */
	private void setNameData(String tableName)
	{
		String query = "";
		
		if (tableName.equals("bankbook"))
		{
			query = "SELECT name FROM ( " +
					"SELECT b.name name FROM bankbook b, bankbook_detail d " +
					"WHERE b.id = d.linkid and d.count > 0 ORDER BY d.count) " +
					"UNION ALL " +
					"SELECT name FROM ( " +
					"SELECT b.name name FROM bankbook b, bankbook_detail d " +
					"WHERE b.id = d.linkid and d.count < 1 ORDER BY d.count);";
		}
		else if (tableName.equals("check_card"))
		{
			query = "SELECT name FROM ( " +
					"SELECT b.name name " +
					"FROM check_card b, checkcard_detail d " +
					"WHERE b.id = d.linkid and d.count > 0 ORDER BY d.count) " +
					"UNION ALL " +
					"SELECT name FROM ( " +
					"SELECT b.name name " +
					"FROM check_card b, checkcard_detail d " +
					"WHERE b.id = d.linkid and d.count < 1 ORDER BY d.count);";
		}
		else if (tableName.equals("credit_card"))
		{
			query = "SELECT name FROM ( " +
					"SELECT b.name name " +
					"FROM credit_card b, creditcard_detail d " +
					"WHERE b.id = d.linkid and d.count > 0 ORDER BY d.count) " +
					"UNION ALL " +
					"SELECT name FROM ( " +
					"SELECT b.name name " +
					"FROM credit_card b, creditcard_detail d " +
					"WHERE b.id = d.linkid and d.count < 1 ORDER BY d.count);";
		}
//		else
//		{
//			query = "SELECT name FROM " + tableName + ";";
//		}
		
		sql.selectMapTile(this, query, new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				nameList = new ArrayList<String>();
				
				int nameIndex = c.getColumnIndex("name");
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					String name = "";
					name = c.getString(nameIndex);
					nameList.add(name);
					
					c.moveToNext();
				}
				
				if (nameList.size() < 1)
				{
					String memo = "없음";
					nameList.add(memo);
					nameView.setClickable(false);
				}
				else
				{
					nameView.setOnClickListener(new OnClickListener()
					{
						@Override
						public void onClick(View v)
						{
							Intent intent = new Intent(SelectUpdateActivity.this, RadioDialogActivity.class);
							intent.putExtra(RadioDialogActivity.RADIODATA, nameList);
							intent.putExtra(RadioDialogActivity.RADIOSELECT, nameTextView.getText().toString());
							startActivityForResult(intent, REQUEST_NAME);
						}
					});
				}
				
				nameTextView.setText(nameList.get(0));
				
//				ArrayAdapter<String> adapter = new ArrayAdapter<String>(
//						SelectUpdateActivity.this, android.R.layout.simple_spinner_item, nameList);
//				adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//				nameSpinner.setAdapter(adapter);
//				nameSpinner.setPrompt("이름");
//				nameSpinner.setSelection(selectIndex);
//				adapter.notifyDataSetChanged();
			}
		});
	}

	private void setClickListener()
	{
		updateButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				if (inMoneyView.getVisibility() == View.VISIBLE)
				{
					if (BDUtil.getCommaDel(inMoneyEditText.getText().toString()).equals("")
							|| BDUtil.getCommaDel(inMoneyEditText.getText().toString()).equals("0"))
					{
						BDUtil.showDialog(SelectUpdateActivity.this, "확인", "금액을 입력해주세요.");
						return;
					}
				}
				else if (outMoneyView.getVisibility() == View.VISIBLE)
				{
					if (BDUtil.getCommaDel(outMoneyEditText.getText().toString()).equals("")
							|| BDUtil.getCommaDel(outMoneyEditText.getText().toString()).equals("0"))
					{
						BDUtil.showDialog(SelectUpdateActivity.this, "확인", "금액을 입력해주세요.");
						return;
					}
				}
				else if (postMoneyView.getVisibility() == View.VISIBLE)
				{
					if (BDUtil.getCommaDel(postMoneyEditText.getText().toString()).equals("") || 
							BDUtil.getCommaDel(postMoneyEditText.getText().toString()).equals("0"))
					{
						BDUtil.showDialog(SelectUpdateActivity.this, "확인", "금액을 입력해주세요.");
						return;
					}
				}
				else if (cashView.getVisibility() == View.VISIBLE)
				{
					if (BDUtil.getCommaDel(cashEditText.getText().toString()).equals("") || 
							BDUtil.getCommaDel(cashEditText.getText().toString()).equals("0"))
					{
						BDUtil.showDialog(SelectUpdateActivity.this, "확인", "금액을 입력해주세요.");
						return;
					}
				}
				
				AlertDialog.Builder dialog = new AlertDialog.Builder(SelectUpdateActivity.this);
				dialog.setIcon(android.R.drawable.ic_dialog_alert);
		    	dialog.setTitle("수정");
		    	dialog.setMessage("데이터를 수정 하시겠습니까?");
		    	dialog.setPositiveButton("수정", new DialogInterface.OnClickListener()
				{
					@Override
					public void onClick(DialogInterface dialog, int which)
					{
						new ShowDialog().execute(0);
						
						dialog.dismiss();
					}
				});
		    	dialog.setNegativeButton("취소", new DialogInterface.OnClickListener()
				{
					@Override
					public void onClick(DialogInterface dialog, int which)
					{
						dialog.dismiss();
					}
				});
		    	
		    	dialog.show();
			}
		});
		
		dateView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
//				DatePickerDialog dpd = new DatePickerDialog(SelectUpdateActivity.this, new OnDateSetListener()
//				{
//					@Override
//					public void onDateSet(DatePicker view, int year, int monthOfYear,
//							int dayOfMonth)
//					{
//						dateTextView.setText(BDUtil.getDate(year, (monthOfYear+1), dayOfMonth));
//						
//						toYear = year;
//						toMonth = monthOfYear;
//						toDay = dayOfMonth;
//					}
//				}, toYear, toMonth, toDay);
//				
//				dpd.show();
				
				CalendarPickerDialog cpd = new CalendarPickerDialog(superContext, new CalendarPickerDialog.ICalendarPickerDateSetListener() {
					@Override
					public void onDateSet(int year, int monthOfYear, int dayOfMonth) {
						
						dateTextView.setText(BDUtil.getDate(year, (monthOfYear+1), dayOfMonth));
						
						toYear = year;
						toMonth = monthOfYear;
						toDay = dayOfMonth;
					}
				}, toYear, toMonth, toDay);
				
				cpd.show();
			}
		});
		
		inMoneyRadio.setOnCheckedChangeListener(new OnCheckedChangeListener()
		{
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
			{
				setCheckInMoneyRadioButton(isChecked);
			}
		});
		
		outMoneyRadio.setOnCheckedChangeListener(new OnCheckedChangeListener()
		{
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
			{
				setCheckOutMoneyRadioButton(isChecked);
			}
		});
	}
	
	private void setCheckInMoneyRadioButton(boolean isChecked)
	{
		if (isChecked)
		{
			inMoneyRadio.setChecked(true);
			outMoneyRadio.setChecked(false);
			
			outMoneyView.setVisibility(View.GONE);
			
			inMoneyView.setVisibility(View.VISIBLE);
			setCategoryData("category_in_list");
			categoryTextView.setText(categoryList.get(0));
		}
	}
	
	private void setCheckOutMoneyRadioButton(boolean isChecked)
	{
		if (isChecked)
		{
			inMoneyRadio.setChecked(false);
			outMoneyRadio.setChecked(true);
			
			inMoneyView.setVisibility(View.GONE);
			
			outMoneyView.setVisibility(View.VISIBLE);
			setCategoryData("category_out_list");
			categoryTextView.setText(categoryList.get(0));
		}
	}

	/**
	 * in_out 테이블을 업데이트 친다.
	 */
	private void setUpdateData()
	{
		HashMap<String, String> map = new HashMap<String, String>();
		
		if (kindView.getVisibility() == View.VISIBLE)
		{
			map.put("linktype", kindTextView.getText().toString());
		}
		
		if (categoryImage.getVisibility() == View.VISIBLE)
		{
			map.put("category", categoryTextView.getText().toString());
			
			String category = categoryTextView.getText().toString();
			
			boolean flag = true;
			
			for (int i = 0; i < fixCategory.length; i++)
			{
				if (category.equals(fixCategory[i]))
				{
					flag = false;
					break;
				}
			}
			
			if (flag)
			{
				setUpdateCategoryData();
			}
		}
		
		if (nameImage.getVisibility() == View.VISIBLE)
		{
			map.put("moneykind", nameTextView.getText().toString());
		}
		
		map.put("date", BDUtil.getDateDB(toYear, toMonth+1, toDay));
		
		if (typeTextView.getText().toString().equals(BDConstents.REAL_MONEY))
		{
			map.put("type", BDConstents.REAL_TYPE);
			
			if (inMoneyView.getVisibility() == View.VISIBLE)
			{
				map.put("inmoney", BDUtil.getCommaDel(inMoneyEditText.getText().toString()));
				map.put("outmoney", "0");
				map.put("postmoney", "0");
			}
			else if (postMoneyView.getVisibility() == View.VISIBLE)
			{
				map.put("inmoney", "0");
				map.put("outmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
				map.put("postmoney", "0");
			}
			else
			{
				map.put("inmoney", "0");
				map.put("outmoney", BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
				map.put("postmoney", "0");
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.BANK_MONEY))
		{
			map.put("type", BDConstents.BANK_TYPE);
			
			if (data.getCategory().equals((BDConstents.CATEGORY_POST_OUT))) 
			{
				map.put("inmoney", "0");
				map.put("outmoney", BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
				map.put("postmoney", "0");
			} 
			else 
			{
				if (inMoneyView.getVisibility() == View.VISIBLE)
				{
					map.put("inmoney", BDUtil.getCommaDel(inMoneyEditText.getText().toString()));
					map.put("outmoney", "0");
					map.put("postmoney", "0");
				}
				else if (postMoneyView.getVisibility() == View.VISIBLE)
				{
					map.put("inmoney", "0");
					map.put("outmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
					map.put("postmoney", "0");
				}
				else
				{
					map.put("inmoney", "0");
					map.put("outmoney", BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
					map.put("postmoney", "0");
				}
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.CHECK_CARD))
		{
			map.put("type", BDConstents.CHECK_TYPE);
			
			if (inMoneyView.getVisibility() == View.VISIBLE)
			{
				map.put("inmoney", BDUtil.getCommaDel(inMoneyEditText.getText().toString()));
				map.put("outmoney", "0");
				map.put("postmoney", "0");
			}
			else if (postMoneyView.getVisibility() == View.VISIBLE)
			{
				map.put("inmoney", "0");
				map.put("outmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
				map.put("postmoney", "0");
			}
			else
			{
				map.put("inmoney", "0");
				map.put("outmoney", BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
				map.put("postmoney", "0");
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.CREDIT_CARD))
		{
			map.put("type", BDConstents.CREDIT_TYPE);
			
			if (postMoneyView.getVisibility() == View.VISIBLE)
			{
				map.put("inmoney", "0");
				map.put("outmoney", "0");
				map.put("postmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
			}
			else if (outMoneyView.getVisibility() == View.VISIBLE)
			{
				map.put("inmoney", "0");
				map.put("outmoney", "0");
				map.put("postmoney", BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.BANK_TO_REAL))
		{
			if (categoryTextView.getText().toString().equals(BDConstents.CATEGORY_SUSUMONEY))
			{
				if (kindTextView.getText().toString().equals(BDConstents.CREDIT_CARD))
				{
					map.put("linktype", BDConstents.CREDIT_TYPE);
					
					map.put("inmoney", "0");
					map.put("outmoney", "0");
					map.put("postmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
				}
				else if (kindTextView.getText().toString().equals(BDConstents.BANK_MONEY))
				{
					map.put("linktype", BDConstents.BANK_TYPE);
					
					map.put("inmoney", "0");
					map.put("outmoney", BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
					map.put("postmoney", "0");
				}
				else if (kindTextView.getText().toString().equals(BDConstents.CHECK_CARD))
				{
					map.put("linktype", BDConstents.CHECK_TYPE);
					
					map.put("inmoney", "0");
					map.put("outmoney", BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
					map.put("postmoney", "0");
				}
			}
			else
			{
				if (kindTextView.getText().toString().equals(BDConstents.BANK_MONEY))
				{
					map.put("linktype", BDConstents.BANK_TYPE);
					
					if (cashView.getVisibility() == View.VISIBLE)
					{
						map.put("inmoney", BDUtil.getCommaDel(cashEditText.getText().toString()));
						map.put("outmoney", BDUtil.getCommaDel(cashEditText.getText().toString()));
						map.put("postmoney", "0");
					}
					else
					{
						map.put("inmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
						map.put("outmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
						map.put("postmoney", "0");
					}
				}
				else if (kindTextView.getText().toString().equals(BDConstents.CHECK_CARD))
				{
					map.put("linktype", BDConstents.CHECK_TYPE);
					
					if (cashView.getVisibility() == View.VISIBLE)
					{
						map.put("inmoney", BDUtil.getCommaDel(cashEditText.getText().toString()));
						map.put("outmoney", BDUtil.getCommaDel(cashEditText.getText().toString()));
						map.put("postmoney", "0");
					}
					else
					{
						map.put("inmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
						map.put("outmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
						map.put("postmoney", "0");
					}
				}
				else if (kindTextView.getText().toString().equals(BDConstents.CREDIT_CARD))
				{
					map.put("linktype", BDConstents.CREDIT_TYPE);
					
					if (cashView.getVisibility() == View.VISIBLE)
					{
						map.put("inmoney", "0");
						map.put("outmoney", "0");
						map.put("postmoney", BDUtil.getCommaDel(cashEditText.getText().toString()));
					}
					else
					{
						map.put("inmoney", "0");
						map.put("outmoney", "0");
						map.put("postmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
					}
				}
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.REAL_TO_BANK))
		{
			if (kindTextView.getText().toString().equals(BDConstents.BANK_MONEY))
			{
				map.put("linktype", BDConstents.BANK_TYPE);
				
				map.put("inmoney", BDUtil.getCommaDel(cashEditText.getText().toString()));
				map.put("outmoney", BDUtil.getCommaDel(cashEditText.getText().toString()));
				map.put("postmoney", "0");
			}
			else if (kindTextView.getText().toString().equals(BDConstents.CHECK_CARD))
			{
				map.put("linktype", BDConstents.CHECK_TYPE);
				
				map.put("inmoney", BDUtil.getCommaDel(cashEditText.getText().toString()));
				map.put("outmoney", BDUtil.getCommaDel(cashEditText.getText().toString()));
				map.put("postmoney", "0");
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.MYBANK_INOUT))
		{
			if (inMoneyView.getVisibility() == View.VISIBLE)
			{
				map.put("linktype", BDConstents.BANK_TYPE);
				
				map.put("inmoney", BDUtil.getCommaDel(inMoneyEditText.getText().toString()));
				map.put("outmoney", "0");
				map.put("postmoney", "0");
			}
			else if (outMoneyView.getVisibility() == View.VISIBLE)
			{
				map.put("linktype", BDConstents.BANK_TYPE);
				
				map.put("inmoney", "0");
				map.put("outmoney", BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
				map.put("postmoney", "0");
			}
			else if (postMoneyView.getVisibility() == View.VISIBLE)
			{
				map.put("linktype", BDConstents.CREDIT_TYPE);
				
				map.put("inmoney", "0");
				map.put("outmoney", "0");
				map.put("postmoney", BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
			}
		}
		
		map.put("memo", memoEditText.getText().toString());
		
		String [] whereArgs = new String[]{data.getId()};
		sql.update(this, "in_out", map, "id = ?", whereArgs);
		
		BalanceQuery balanceQuery = new BalanceQuery(superContext);
		
		// 수정에 의한 롤백 처리 반대로 처리
		if (data.getType().toString().equals(BDConstents.REAL_TYPE))
		{
			if (inMoneyView.getVisibility() == View.VISIBLE)
			{
				setRealMoneyData(0, data.getInMoney());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.REAL_TYPE, BDConstents.REAL_MONEY, 
						BDUtil.getCommaDel(data.getInMoney()), 0);
			}
			else
			{
				setRealMoneyData(1, data.getOutMoney());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.REAL_TYPE, BDConstents.REAL_MONEY, 
						BDUtil.getCommaDel(data.getOutMoney()), 1);
			}
		}
		else if (data.getType().toString().equals(BDConstents.BANK_TYPE))
		{
			if (inMoneyView.getVisibility() == View.VISIBLE) 
			{
				setBankMoney(0, data.getInMoney(), data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getInMoney()), 0);
			} 
			else 
			{
				setBankMoney(1, data.getOutMoney(), data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getOutMoney()), 1);
				
				if (categoryTextView.getText().equals(BDConstents.CATEGORY_POST_OUT))
				{
					setCreditCard(1, data.getOutMoney(), data.getPostMoneyKind());
				}
			}
		}
		else if (data.getType().toString().equals(BDConstents.CHECK_TYPE))
		{
			if (inMoneyView.getVisibility() == View.VISIBLE) 
			{
				setCheckCard(0, data.getInMoney(), data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getInMoney()), 0);
			} 
			else 
			{
				setCheckCard(1, data.getOutMoney(), data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getOutMoney()), 1);
			}
		}
		else if (data.getType().toString().equals(BDConstents.CREDIT_TYPE))
		{
			setCreditCard(0, data.getPostMoney(), data.getMoneyKind());
			
			// 잔액을 수정 한다.
			balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, data.getMoneyKind(), 
					BDUtil.getCommaDel(data.getPostMoney()), 0);
		}
		else if (data.getType().toString().equals(BDConstents.MYBANK_INOUT_TYPE))
		{
			boolean flag = true;
			
			if (categoryTextView.getText().toString().equals(BDConstents.CATEGORY_SUSUMONEY))
			{
				flag = false;
			}
			
			if (outMoneyView.getVisibility() == View.VISIBLE)
			{
				setBankMoney(1, data.getOutMoney(), data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getOutMoney()), 1);
				
				if (flag)
				{
					setBankMoney(0, data.getOutMoney(), 
							getInOutName(0, data.getLinkId(), data.getOutMoney(), 1));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, getData.getMoneyKind(), 
							BDUtil.getCommaDel(data.getOutMoney()), 0);
				}
			}
			else if (postMoneyView.getVisibility() == View.VISIBLE)
			{
				setCreditCard(0, data.getPostMoney(), 
						data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getPostMoney()), 0);
				
				if (flag)
				{
					setBankMoney(0, data.getPostMoney(), 
							getInOutName(0, data.getLinkId(), data.getPostMoney(), 1));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, getData.getMoneyKind(), 
							BDUtil.getCommaDel(data.getPostMoney()), 0);
				}
			}
			else
			{
				setBankMoney(0, data.getInMoney(), data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getInMoney()), 0);
				
				if (flag)
				{
					String cardName = getInOutName(0, data.getLinkId(), data.getInMoney(), 0);
					
					if (getData != null)
					{
						if (getData.getLinktype().equals(BDConstents.CREDIT_TYPE))
						{
							setCreditCard(0, data.getInMoney(), cardName);
							
							// 잔액을 수정 한다.
							balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.CREDIT_TYPE, cardName, 
									BDUtil.getCommaDel(data.getInMoney()), 0);
						}
						else
						{
							setBankMoney(1, data.getInMoney(), cardName);
							
							// 잔액을 수정 한다.
							balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.BANK_TYPE, cardName, 
									BDUtil.getCommaDel(data.getInMoney()), 1);
						}
					}
					
				}
			}
		}
		else if (data.getType().toString().equals(BDConstents.INOUT_TYPE))
		{
			if (categoryTextView.getText().toString().equals(BDConstents.CATEGORY_SUSUMONEY))
			{
				if (outMoneyView.getVisibility() == View.VISIBLE)
				{
					if (data.getLinktype().toString().equals(BDConstents.BANK_TYPE))
					{
						setBankMoney(1, data.getOutMoney(), data.getMoneyKind());
						
						// 잔액을 수정 한다.
						balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, data.getMoneyKind(), 
								BDUtil.getCommaDel(data.getOutMoney()), 1);
					}
					else if (data.getLinktype().toString().equals(BDConstents.CHECK_TYPE))
					{
						setCheckCard(1, data.getOutMoney(), data.getMoneyKind());
						
						// 잔액을 수정 한다.
						balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, data.getMoneyKind(), 
								BDUtil.getCommaDel(data.getOutMoney()), 1);
					}
				}
				else
				{
					setCreditCard(0, data.getPostMoney(), data.getMoneyKind());
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, data.getMoneyKind(), 
							BDUtil.getCommaDel(data.getPostMoney()), 0);
				}
			}
			else if (data.getLinktype().toString().equals(BDConstents.BANK_TYPE))
			{
				setBankMoney(1, data.getOutMoney(), data.getMoneyKind());
				
				setRealMoneyData(0, data.getOutMoney());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getOutMoney()), 1);
				
				// 수수료에 대한 처리
				setBankMoney(1, getInOutMoney(data.getLinkId()), 
						data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.BANK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(getInOutMoney(data.getLinkId())), 1);
			}
			else if (data.getLinktype().toString().equals(BDConstents.CHECK_TYPE))
			{
				setCheckCard(1, data.getOutMoney(), data.getMoneyKind());
				
				setRealMoneyData(0, data.getOutMoney());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getOutMoney()), 1);
				
				// 수수료에 대한 처리
				setCheckCard(1, getInOutMoney(data.getLinkId()), 
						data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.CHECK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(getInOutMoney(data.getLinkId())), 1);
			}
			else if (data.getLinktype().toString().equals(BDConstents.CREDIT_TYPE))
			{
				setCreditCard(0, data.getPostMoney(), data.getMoneyKind());
				
				setRealMoneyData(0, data.getPostMoney());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getPostMoney()), 0);
				
				// 수수료에 대한 처리
				setCreditCard(0, getInOutMoney(data.getLinkId()), 
						data.getMoneyKind());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.CREDIT_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(getInOutMoney(data.getLinkId())), 0);
			}
		}
		else if (data.getType().toString().equals(BDConstents.OUTIN_TYPE))
		{
			if (data.getLinktype().toString().equals(BDConstents.BANK_TYPE))
			{
				setBankMoney(0, data.getOutMoney(), data.getMoneyKind());
				setRealMoneyData(1, data.getOutMoney());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getOutMoney()), 0);
			}
			else if (data.getLinktype().toString().equals(BDConstents.CHECK_TYPE))
			{
				setCheckCard(0, data.getOutMoney(), data.getMoneyKind());
				setRealMoneyData(1, data.getOutMoney());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, data.getMoneyKind(), 
						BDUtil.getCommaDel(data.getOutMoney()), 0);
			}
		}
		
		// 수정에 의한 데이터 삽입 처리 부분
		if (typeTextView.getText().toString().equals(BDConstents.REAL_MONEY))
		{
			if (outMoneyView.getVisibility() == View.VISIBLE)
			{
				setRealMoneyData(0, BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.REAL_TYPE, BDConstents.REAL_MONEY, 
						BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 0);
			}
			else if (postMoneyView.getVisibility() == View.VISIBLE)
			{
				setRealMoneyData(0, BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.REAL_TYPE, BDConstents.REAL_MONEY, 
						BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 0);
			}
			else
			{
				setRealMoneyData(1, BDUtil.getCommaDel(inMoneyEditText.getText().toString()));
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.REAL_TYPE, BDConstents.REAL_MONEY, 
						BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 1);
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.BANK_MONEY))
		{
			if (inMoneyView.getVisibility() == View.VISIBLE) 
			{
				setBankMoney(1, BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 1);
			} 
			else if (postMoneyView.getVisibility() == View.VISIBLE)
			{
				setBankMoney(0, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 0);
				
				if (categoryTextView.getText().equals(BDConstents.CATEGORY_POST_OUT))
				{
					setCreditCard(0, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 
							data.getPostMoneyKind());
				}
			}
			else 
			{
				setBankMoney(0, BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 0);
				
				if (categoryTextView.getText().equals(BDConstents.CATEGORY_POST_OUT))
				{
					setCreditCard(0, BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 
							data.getPostMoneyKind());
				}
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.CHECK_CARD))
		{
			if (outMoneyView.getVisibility() == View.VISIBLE) 
			{
				setCheckCard(0, BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 0);
			} 
			else if (postMoneyView.getVisibility() == View.VISIBLE)
			{
				setCheckCard(0, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 0);
			}
			else 
			{
				setCheckCard(1, BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 1);
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.CREDIT_CARD))
		{
			if (outMoneyView.getVisibility() == View.VISIBLE)
			{
				setCreditCard(1, BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 1);
			}
			else
			{
				setCreditCard(1, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 1);
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.MYBANK_INOUT))
		{
			boolean flag = true;
			
			if (categoryTextView.getText().toString().equals(BDConstents.CATEGORY_SUSUMONEY))
			{
				flag = false;
			}
			
			if (outMoneyView.getVisibility() == View.VISIBLE)
			{
				setBankMoney(0, BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 0);
				
				if (flag)
				{
					setBankMoney(1, BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 
							getInOutName(1, data.getLinkId(), BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 1));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.BANK_TYPE, getData.getMoneyKind(), 
							BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 1);
				}
			}
			else if (postMoneyView.getVisibility() == View.VISIBLE)
			{
				setCreditCard(1, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 1);
				
				if (flag)
				{
					setBankMoney(1, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 
							getInOutName(1, data.getLinkId(), BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 1));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, getData.getMoneyKind(), 
							BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 1);
				}
			}
			else
			{
				setBankMoney(1, BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 
						nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 1);
				
				if (flag)
				{
					String cardName = getInOutName(1, data.getLinkId(), 
							BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 0);
					
					if (getData != null)
					{
						if (getData.getLinktype().equals(BDConstents.CREDIT_TYPE))
						{
							setCreditCard(1, BDUtil.getCommaDel(inMoneyEditText.getText().toString()), cardName);
							
							// 잔액을 수정 한다.
							balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.CREDIT_TYPE, cardName, 
									BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 1);
						}
						else
						{
							setBankMoney(0, BDUtil.getCommaDel(inMoneyEditText.getText().toString()), cardName);
							
							// 잔액을 수정 한다.
							balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.BANK_TYPE, cardName, 
									BDUtil.getCommaDel(inMoneyEditText.getText().toString()), 0);
						}
					}
					
				}
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.BANK_TO_REAL))
		{
			if (categoryTextView.getText().toString().equals(BDConstents.CATEGORY_SUSUMONEY))
			{
				if (outMoneyView.getVisibility() == View.VISIBLE)
				{
					if (kindTextView.getText().toString().equals(BDConstents.BANK_MONEY))
					{
						setBankMoney(0, BDUtil.getCommaDel(outMoneyEditText.getText().toString()), nameTextView.getText().toString());
						
						// 잔액을 수정 한다.
						balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
								BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 0);
					}
					else if (kindTextView.getText().toString().equals(BDConstents.CHECK_CARD))
					{
						setCheckCard(0, BDUtil.getCommaDel(outMoneyEditText.getText().toString()), nameTextView.getText().toString());
						
						// 잔액을 수정 한다.
						balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
								BDUtil.getCommaDel(outMoneyEditText.getText().toString()), 0);
					}
				}
				else
				{
					setCreditCard(1, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), nameTextView.getText().toString());
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 1);
				}
			}
			else if (kindTextView.getText().toString().equals(BDConstents.BANK_MONEY))
			{
				if (cashView.getVisibility() == View.VISIBLE)
				{
					setBankMoney(0, BDUtil.getCommaDel(cashEditText.getText().toString()), nameTextView.getText().toString());
					setRealMoneyData(1, BDUtil.getCommaDel(cashEditText.getText().toString()));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(cashEditText.getText().toString()), 0);
					
					// 수수료에 대한 처리
					setBankMoney(0, getInOutMoney(data.getLinkId()), 
							nameTextView.getText().toString());
					setInOutTypeUpdate(data.getLinkId(), BDConstents.BANK_TYPE, nameTextView.getText().toString());
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(getInOutMoney(data.getLinkId())), 0);
				}
				else
				{
					setBankMoney(0, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), nameTextView.getText().toString());
					setRealMoneyData(1, BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 0);
					
					// 수수료에 대한 처리
					setBankMoney(0, getInOutMoney(data.getLinkId()), 
							nameTextView.getText().toString());
					setInOutTypeUpdate(data.getLinkId(), BDConstents.BANK_TYPE, nameTextView.getText().toString());
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(getInOutMoney(data.getLinkId())), 0);
				}
			}
			else if (kindTextView.getText().equals(BDConstents.CHECK_CARD))
			{
				if (cashView.getVisibility() == View.VISIBLE)
				{
					setCheckCard(0, BDUtil.getCommaDel(cashEditText.getText().toString()), nameTextView.getText().toString());
					setRealMoneyData(1, BDUtil.getCommaDel(cashEditText.getText().toString()));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(cashEditText.getText().toString()), 0);
					
					// 수수료에 대한 처리
					setCheckCard(0, getInOutMoney(data.getLinkId()), 
							nameTextView.getText().toString());
					setInOutTypeUpdate(data.getLinkId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString());
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(getInOutMoney(data.getLinkId())), 0);
				}
				else
				{
					setCheckCard(0, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), nameTextView.getText().toString());
					setRealMoneyData(1, BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 0);
					
					// 수수료에 대한 처리
					setCheckCard(0, getInOutMoney(data.getLinkId()), 
							nameTextView.getText().toString());
					setInOutTypeUpdate(data.getLinkId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString());
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(getInOutMoney(data.getLinkId())), 0);
				}
			}
			else if (kindTextView.getText().equals(BDConstents.CREDIT_CARD))
			{
				if (cashView.getVisibility() == View.VISIBLE)
				{
					setCreditCard(1, BDUtil.getCommaDel(cashEditText.getText().toString()), nameTextView.getText().toString());
					setRealMoneyData(1, BDUtil.getCommaDel(cashEditText.getText().toString()));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(cashEditText.getText().toString()), 1);
					
					// 수수료에 대한 처리
					setCreditCard(1, getInOutMoney(data.getLinkId()), 
							nameTextView.getText().toString());
					setInOutTypeUpdate(data.getLinkId(), BDConstents.CREDIT_TYPE, nameTextView.getText().toString());
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.CREDIT_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(getInOutMoney(data.getLinkId())), 1);
				}
				else
				{
					setCreditCard(1, BDUtil.getCommaDel(postMoneyEditText.getText().toString()), nameTextView.getText().toString());
					setRealMoneyData(1, BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CREDIT_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(postMoneyEditText.getText().toString()), 1);
					
					// 수수료에 대한 처리
					setCreditCard(1, getInOutMoney(data.getLinkId()), 
							nameTextView.getText().toString());
					setInOutTypeUpdate(data.getLinkId(), BDConstents.CREDIT_TYPE, nameTextView.getText().toString());
					
					// 잔액을 수정 한다.
					balanceQuery.setBalanceUpdateRollBank(data.getLinkId(), BDConstents.CREDIT_TYPE, nameTextView.getText().toString(), 
							BDUtil.getCommaDel(getInOutMoney(data.getLinkId())), 1);
				}
			}
		}
		else if (typeTextView.getText().toString().equals(BDConstents.REAL_TO_BANK))
		{
			if (kindTextView.getText().equals(BDConstents.BANK_MONEY))
			{
				setBankMoney(1, BDUtil.getCommaDel(cashEditText.getText().toString()), nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.BANK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(cashEditText.getText().toString()), 1);
			}
			else if (kindTextView.getText().equals(BDConstents.CHECK_CARD))
			{
				setCheckCard(1, BDUtil.getCommaDel(cashEditText.getText().toString()), nameTextView.getText().toString());
				
				// 잔액을 수정 한다.
				balanceQuery.setBalanceUpdateRollBank(data.getId(), BDConstents.CHECK_TYPE, nameTextView.getText().toString(), 
						BDUtil.getCommaDel(cashEditText.getText().toString()), 1);
			}
			
			setRealMoneyData(0, BDUtil.getCommaDel(cashEditText.getText().toString()));
		}
	}

	private SelectData getData = null;
	/**
	 * in_out 테이블에서 Id로 통장이나 카드 이름을 가져온다.
	 * @param flag 0 = 금액에서 돈을 뺀다. 1 = 금액에서 돈을 더한다. 
	 * @param moneyFlag 0 = outmoney 1 = inmoney, 2 = postmoney 
	 * @param linkId
	 */
	private String getInOutName(final int flag, String linkId, final String bankMoney, final int moneyFlag)
	{
		getData = null;
		
		sql.selectMapTile(this, "SELECT * FROM in_out WHERE id = " + linkId + ";", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				getData = new SelectData();
				
				int id = c.getColumnIndex("id");
				int category = c.getColumnIndex("category");
				int memo = c.getColumnIndex("memo");
				int inmoney = c.getColumnIndex("inmoney");
				int outmoney = c.getColumnIndex("outmoney");
				int date = c.getColumnIndex("date");
				int moneykind = c.getColumnIndex("moneykind");
				int postmoneykind = c.getColumnIndex("postmoneykind");
				int postmoney = c.getColumnIndex("postmoney");
				int type = c.getColumnIndex("type");
				int linkid = c.getColumnIndex("linkid");
				int linktype = c.getColumnIndex("linktype");
				int deleteyn = c.getColumnIndex("deleteyn");
				
				BigDecimal money = BigDecimal.ZERO;
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					getData.setId(c.getInt(id) + "");
					getData.setCategory(c.getString(category));
					getData.setMemo(c.getString(memo));
					getData.setInMoney(c.getString(inmoney));
					getData.setOutMoney(c.getString(outmoney));
					getData.setPostMoney(c.getString(postmoney));
					getData.setDate(c.getInt(date) + "");
					getData.setMoneyKind(c.getString(moneykind));
					getData.setPostMoneyKind(c.getString(postmoneykind));
					getData.setType(c.getInt(type) + "");
					getData.setLinkId(c.getInt(linkid) + "");
					getData.setLinktype(c.getInt(linktype) + "");
					getData.setDeleteYn(c.getInt(deleteyn) + "");
					
					c.moveToNext();
				}
				
				if (getData != null)
				{
					
					HashMap<String, String> map = new HashMap<String, String>();
					
					if (flag == 0)
					{
						if (moneyFlag == 0)
						{
							if (getData.getLinktype().equals(BDConstents.CREDIT_TYPE))
							{
								money = new BigDecimal(getData.getPostMoney());
								money = money.subtract(new BigDecimal(bankMoney));
								map.put("postmoney", money.toString());
							}
							else
							{
								money = new BigDecimal(getData.getOutMoney());
								money = money.subtract(new BigDecimal(bankMoney));
								map.put("outmoney", money.toString());
							}
						}
						else if (moneyFlag == 1)
						{
							money = new BigDecimal(getData.getInMoney());
							money = money.subtract(new BigDecimal(bankMoney));
							map.put("inmoney", money.toString());
						}
					}
					else if (flag == 1)
					{
						if (moneyFlag == 0)
						{
							if (getData.getLinktype().equals(BDConstents.CREDIT_TYPE))
							{
								money = new BigDecimal(getData.getPostMoney());
								money = money.add(new BigDecimal(bankMoney));
								map.put("postmoney", money.toString());
							}
							else
							{
								money = new BigDecimal(getData.getOutMoney());
								money = money.add(new BigDecimal(bankMoney));
								map.put("outmoney", money.toString());
							}
						}
						else if (moneyFlag == 1)
						{
							money = new BigDecimal(getData.getInMoney());
							money = money.add(new BigDecimal(bankMoney));
							map.put("inmoney", money.toString());
						}
					}
					
					String [] whereArgs = new String[]{getData.getId()};
					sql.update(superContext, "in_out", map, "id = ?", whereArgs);
				}
			}
		});
		
		if (getData != null)
		{
			return getData.getMoneyKind();
		}
		
		return "";
	}
	
	/**
	 * in_out 테이블에서 Id로 수수료 금액을 가져온다.
	 * @param flag 0 = 금액에서 돈을 뺀다. 1 = 금액에서 돈을 더한다. 
	 * @param moneyFlag 0 = outmoney 1 = inmoney, 2 = postmoney 
	 * @param linkId
	 */
	private String getInOutMoney(String linkId)
	{
		String money = "0";
		getData = null;
		
		sql.selectMapTile(this, "SELECT * FROM in_out WHERE id = " + linkId + ";", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				getData = new SelectData();
				
				int id = c.getColumnIndex("id");
				int category = c.getColumnIndex("category");
				int memo = c.getColumnIndex("memo");
				int inmoney = c.getColumnIndex("inmoney");
				int outmoney = c.getColumnIndex("outmoney");
				int date = c.getColumnIndex("date");
				int moneykind = c.getColumnIndex("moneykind");
				int postmoneykind = c.getColumnIndex("postmoneykind");
				int postmoney = c.getColumnIndex("postmoney");
				int type = c.getColumnIndex("type");
				int linkid = c.getColumnIndex("linkid");
				int linktype = c.getColumnIndex("linktype");
				int deleteyn = c.getColumnIndex("deleteyn");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					getData.setId(c.getInt(id) + "");
					getData.setCategory(c.getString(category));
					getData.setMemo(c.getString(memo));
					getData.setInMoney(c.getString(inmoney));
					getData.setOutMoney(c.getString(outmoney));
					getData.setPostMoney(c.getString(postmoney));
					getData.setDate(c.getInt(date) + "");
					getData.setMoneyKind(c.getString(moneykind));
					getData.setPostMoneyKind(c.getString(postmoneykind));
					getData.setType(c.getInt(type) + "");
					getData.setLinkId(c.getInt(linkid) + "");
					getData.setLinktype(c.getInt(linktype) + "");
					getData.setDeleteYn(c.getInt(deleteyn) + "");
					
					c.moveToNext();
				}
			}
		});
		
		if (getData != null)
		{
			if (getData.getOutMoney() != null && !getData.getOutMoney().equals("0"))
			{
				money = getData.getOutMoney();
			}
			else if (getData.getPostMoney() != null && !getData.getPostMoney().equals("0"))
			{
				money = getData.getPostMoney();
			}
			else if (getData.getInMoney() != null && !getData.getInMoney().equals("0"))
			{
				money = getData.getInMoney();
			}
		}
		
		return money;
	}
	
	/**
	 * 수수료에 의한 in_out 테이블 타입 업데이트
	 * @param linkId
	 * @param typeFlag 
	 * @param moneyKind
	 */
	private void setInOutTypeUpdate(String linkId, final String typeFlag, final String moneyKind)
	{
		getData = null;
		
		sql.selectMapTile(this, "SELECT * FROM in_out WHERE id = " + linkId + ";", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				getData = new SelectData();
				
				int id = c.getColumnIndex("id");
				int category = c.getColumnIndex("category");
				int memo = c.getColumnIndex("memo");
				int inmoney = c.getColumnIndex("inmoney");
				int outmoney = c.getColumnIndex("outmoney");
				int date = c.getColumnIndex("date");
				int moneykind = c.getColumnIndex("moneykind");
				int postmoneykind = c.getColumnIndex("postmoneykind");
				int postmoney = c.getColumnIndex("postmoney");
				int type = c.getColumnIndex("type");
				int linkid = c.getColumnIndex("linkid");
				int linktype = c.getColumnIndex("linktype");
				int deleteyn = c.getColumnIndex("deleteyn");
				
				BigDecimal money = BigDecimal.ZERO;
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					getData.setId(c.getInt(id) + "");
					getData.setCategory(c.getString(category));
					getData.setMemo(c.getString(memo));
					getData.setInMoney(c.getString(inmoney));
					getData.setOutMoney(c.getString(outmoney));
					getData.setPostMoney(c.getString(postmoney));
					getData.setDate(c.getInt(date) + "");
					getData.setMoneyKind(c.getString(moneykind));
					getData.setPostMoneyKind(c.getString(postmoneykind));
					getData.setType(c.getInt(type) + "");
					getData.setLinkId(c.getInt(linkid) + "");
					getData.setLinktype(c.getInt(linktype) + "");
					getData.setDeleteYn(c.getInt(deleteyn) + "");
					
					c.moveToNext();
				}
				
				if (getData != null)
				{
					
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("moneykind", moneyKind);
					map.put("linktype", typeFlag);
					map.put("date", BDUtil.getDateDB(toYear, toMonth+1, toDay));
					
					if (typeFlag.equals(BDConstents.CREDIT_TYPE))
					{
						if (!data.getLinktype().equals(BDConstents.CREDIT_TYPE))
						{
							map.put("outmoney", "0");
							map.put("postmoney", getData.getOutMoney());
						}
					}
					else
					{
						if (data.getLinktype().equals(BDConstents.CREDIT_TYPE))
						{
							map.put("outmoney", getData.getPostMoney());
							map.put("postmoney", "0");
						}
					}
					
					String [] whereArgs = new String[]{getData.getId()};
					sql.update(superContext, "in_out", map, "id = ?", whereArgs);
				}
			}
		});
	}

	private CategoryData categoryData = null;
	/**
	 * 카테고리 데이터의 빈도수를 하나 올린다.
	 */
	private void setUpdateCategoryData()
	{
		if (data.getCategory().equals(categoryTextView.getText().toString()))
		{
			return;
		}
		
		String tableName = "category_in_list";
		
		if (categoryInOutFlag == 0)
		{
			tableName = "category_in_list";
		}
		else if(categoryInOutFlag ==1)
		{
			tableName = "category_out_list";
		}
		else
		{
			tableName = "category_move_list";
		}
		
		sql.selectMapTile(this, "SELECT * FROM " + tableName + " WHERE kind = '" 
				+ BDUtil.getApostrophe(categoryTextView.getText().toString()) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				categoryData = new CategoryData();
				
				int idIdx = c.getColumnIndex("id");
				int kindIdx = c.getColumnIndex("kind");
				int countIdx = c.getColumnIndex("count");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					categoryData.setId(c.getInt(idIdx) + "");
					categoryData.setKind(c.getString(kindIdx));
					categoryData.setCount(c.getInt(countIdx) + "");
					c.moveToNext();
				}
				
				if (categoryData.getCount().equals("0"))
				{
					return;
				}
			}
		});
		
		if (categoryData  != null)
		{
			int count = Integer.parseInt(categoryData.getCount());
			count--;
			
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("count", count + "");
			String [] whereArgs = new String[]{data.getId() + ""};
			sql.update(this, tableName, map, "id = ?", whereArgs);
		}
	}

	/**
	 * 현금 테이블을 데이터 변경한다.
	 * flag = 0 값을 뺀다, 1 값을 더한다
	 */
	private void setRealMoneyData(final int flag, final String realMoney)
	{
		sql.selectMapTile(this, "SELECT money FROM real_money;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int moneyIdx = c.getColumnIndex("money");
				
				c.moveToFirst();
//				int money = 0;
				BigDecimal money = BigDecimal.ZERO;
				for (int i = 0; i < c.getCount(); i++)
				{
//					money = money + Integer.parseInt(c.getString(moneyIdx));
					money = money.add(new BigDecimal(c.getString(moneyIdx)));
					c.moveToNext();
				}
				
				if (flag == 0)
				{
					money = money.subtract(new BigDecimal(realMoney.toString()));
				}
				else
				{
					money = money.add(new BigDecimal(realMoney.toString()));
				}
				
				HashMap<String, String> map = new HashMap<String, String>();
				map.put("money", money.toString());
				sql.update(SelectUpdateActivity.this, "real_money", map, null, null);
			}
		});
	}
	
	/**
	 * 통장 테이블의 금액을 변경한다.
	 * flag 0 = 금액을 뺀다, 1 = 금액을 더한다
	 */
	private void setBankMoney(final int flag, final String bankMoney, String bankName)
	{
		String query = "";
		
		query = "SELECT id, money FROM bankbook WHERE name = '" + BDUtil.getApostrophe(bankName) + "';";
			
		sql.selectMapTile(this, query, new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int moneyIdx = c.getColumnIndex("money");
				int idIdx = c.getColumnIndex("id");
				
				c.moveToFirst();
				BigDecimal money = BigDecimal.ZERO;
				int id = -1;
				for (int i = 0; i < c.getCount(); i++)
				{
					money = money.add(new BigDecimal(c.getString(moneyIdx)));
					id = c.getInt(idIdx);
					c.moveToNext();
				}
				
				if (id > -1)
				{
					if (flag == 0)
					{
						money = money.subtract(new BigDecimal(bankMoney));
					}
					else
					{
						money = money.add(new BigDecimal(bankMoney));
					}
					
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("money", money.toString());
					String [] whereArgs = new String[]{id + ""};
					sql.update(SelectUpdateActivity.this, "bankbook", map, "id = ?", whereArgs);
				}
			}
		});
	}
	
	/**
	 * 체크카드 금액을 변경한다.
	 * flag 0 = 금액을 뺀다, 1 = 금액을 더한다.
	 */
	private void setCheckCard(final int flag, final String cardMoney, final String cardName)
	{
		sql.selectMapTile(this, "SELECT * FROM check_card WHERE name = '"
				+ BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int banklinkIdx = c.getColumnIndex("banklink");
				
				c.moveToFirst();
				
				int linkId = -1;
				
				for (int i = 0; i < c.getCount(); i++)
				{
					linkId = c.getInt(banklinkIdx);
					c.moveToNext();
				}
				
				if (linkId > -1)
				{
					setBankBookId(flag, cardMoney, linkId + "");
				}
			}
		});
	}
	
	/**
	 * 체크카드에 의한 통장을 변경한다.
	 * @param flag 0 = 금액을 뺀다, 1 = 금액을 더한다.
	 * @param cardMoney
	 * @param linkId
	 */
	private void setBankBookId(final int flag, final String cardMoney, String linkId)
	{
		String query = "";
		
		query = "SELECT id, money FROM bankbook WHERE id = " + linkId + ";";
			
		sql.selectMapTile(this, query, new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int moneyIdx = c.getColumnIndex("money");
				int idIdx = c.getColumnIndex("id");
				
				c.moveToFirst();
				BigDecimal money = BigDecimal.ZERO;
				int id = -1;
				for (int i = 0; i < c.getCount(); i++)
				{
					money = money.add(new BigDecimal(c.getString(moneyIdx)));
					id = c.getInt(idIdx);
					c.moveToNext();
				}
				
				if (id > -1)
				{
					if (flag == 0)
					{
						money = money.subtract(new BigDecimal(cardMoney));
					}
					else
					{
						money = money.add(new BigDecimal(cardMoney));
					}
					
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("money", money.toString());
					String [] whereArgs = new String[]{id + ""};
					sql.update(SelectUpdateActivity.this, "bankbook", map, "id = ?", whereArgs);
				}
			}
		});
	}
	
	/**
	 * 신용카드 금액을 변경한다.
	 * flag 0 = 금액을 뺀다, 1 = 금액을 더한다
	 */
	private void setCreditCard(final int flag, final String cardMoney, final String cardName) 
	{
		sql.selectMapTile(this, "SELECT outmoney FROM credit_card WHERE name = '" + 
									BDUtil.getApostrophe(cardName) + "';", 
				new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int outmoneyIdx = c.getColumnIndex("outmoney");
				
				c.moveToFirst();
				BigDecimal money = BigDecimal.ZERO;
				for (int i = 0; i < c.getCount(); i++)
				{
					money = money.add(new BigDecimal(c.getString(outmoneyIdx)));
					c.moveToNext();
				}
				
				if (flag == 0)
				{
					money = money.subtract(new BigDecimal(cardMoney));
				}
				else
				{
					money = money.add(new BigDecimal(cardMoney));
				}
				
				HashMap<String, String> map = new HashMap<String, String>();
				map.put("outmoney", money.toString());
				String [] whereArgs = new String[]{cardName};
				sql.update(SelectUpdateActivity.this, "credit_card", map, "name = ?", whereArgs);
			}
		});
	}
	
	/**
	 * 총 금액을 롤백한다.
	 */
	private void setTotalMoneyRollBack()
	{
		sql.selectMapTile(this, "SELECT money FROM total_money;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
//				int money = 0;
				BigDecimal money = BigDecimal.ZERO;
				int moneyIdx = c.getColumnIndex("money");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
//					money = money + Integer.parseInt(c.getString(moneyIdx));
					money = money.add(new BigDecimal(c.getString(moneyIdx)));
					c.moveToNext();
				}
				
				if (data.getCategory().equals(BDConstents.CATEGORY_SUSUMONEY))
				{
					if (!data.getLinktype().equals(BDConstents.CREDIT_TYPE))
					{
//						money = money + Integer.parseInt(data.getOutMoney());
						money = money.add(new BigDecimal(data.getOutMoney()));
						
//						money = money - Integer.parseInt(BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
						money = money.subtract(new BigDecimal(BDUtil.getCommaDel(outMoneyEditText.getText().toString())));
					}
				}
				else if (moneyRadioView.getVisibility() == View.VISIBLE)
				{
					if (inMoneyRadio.isChecked())
					{
//						money = money + Integer.parseInt(data.getOutMoney());
						money = money.add(new BigDecimal(data.getOutMoney()));
						
//						money = money - Integer.parseInt(data.getInMoney());
						money = money.subtract(new BigDecimal(data.getInMoney()));
						
//						money = money + Integer.parseInt(BDUtil.getCommaDel(inMoneyEditText.getText().toString()));
						money = money.add(new BigDecimal(BDUtil.getCommaDel(inMoneyEditText.getText().toString())));
					}
					else if (outMoneyRadio.isChecked())
					{
//						money = money - Integer.parseInt(data.getInMoney());
						money = money.subtract(new BigDecimal(data.getInMoney()));
						
//						money = money + Integer.parseInt(data.getOutMoney());
						money = money.add(new BigDecimal(data.getOutMoney()));
						
//						money = money - Integer.parseInt(BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
						money = money.subtract(new BigDecimal(BDUtil.getCommaDel(outMoneyEditText.getText().toString())));
					}
				}
				else if (moneyRadioView.getVisibility() == View.GONE)
				{
					if (data.getType().equals(BDConstents.BANK_TYPE))
					{
						if (data.getCategory().equals(BDConstents.CATEGORY_POST_OUT)) 
						{
//							money = money + Integer.parseInt(data.getOutMoney());
							money = money.add(new BigDecimal(data.getOutMoney()));
							
//							money = money - Integer.parseInt(data.getInMoney());
							money = money.subtract(new BigDecimal(data.getInMoney()));
							
//							money = money - Integer.parseInt(BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
							money = money.subtract(new BigDecimal(BDUtil.getCommaDel(outMoneyEditText.getText().toString())));
						} 
						else 
						{
//							money = money + Integer.parseInt(data.getOutMoney());
							money = money.add(new BigDecimal(data.getOutMoney()));
							
//							money = money - Integer.parseInt(data.getInMoney());
							money = money.subtract(new BigDecimal(data.getInMoney()));
							
//							money = money + Integer.parseInt(BDUtil.getCommaDel(inMoneyEditText.getText().toString()));
							money = money.add(new BigDecimal(BDUtil.getCommaDel(inMoneyEditText.getText().toString())));
						}
					}
					else if (data.getType().equals(BDConstents.CHECK_TYPE))
					{
//						money = money - Integer.parseInt(data.getInMoney());
						money = money.subtract(new BigDecimal(data.getInMoney()));
						
//						money = money + Integer.parseInt(data.getOutMoney());
						money = money.add(new BigDecimal(data.getOutMoney()));
						
//						money = money - Integer.parseInt(BDUtil.getCommaDel(outMoneyEditText.getText().toString()));
						money = money.subtract(new BigDecimal(BDUtil.getCommaDel(outMoneyEditText.getText().toString())));
					}
					else if (data.getType().equals(BDConstents.INOUT_TYPE))
					{
						if (data.getLinktype().equals(BDConstents.CREDIT_TYPE))
						{
//							money = money - Integer.parseInt(data.getPostMoney());
							money = money.subtract(new BigDecimal(data.getPostMoney()));
							
//							money = money + Integer.parseInt(BDUtil.getCommaDel(postMoneyEditText.getText().toString()));
							money = money.add(new BigDecimal(BDUtil.getCommaDel(postMoneyEditText.getText().toString())));
						}
					}
				}
				
				HashMap<String, String> map = new HashMap<String, String>();
				map.put("money", money.toString());
				sql.update(SelectUpdateActivity.this, "total_money", map, null, null);
			}
		});
	}
	
	/**
	 * 타입 처리 부분
	 * @param map
	 */
	private void setTypeHashMap(HashMap<String, String> map)
	{
		if (typeTextView.getVisibility() == View.VISIBLE)
		{
			if (typeTextView.equals(BDConstents.REAL_MONEY))
			{
				map.put("type", BDConstents.REAL_TYPE);
			}
			else if (typeTextView.equals(BDConstents.BANK_MONEY))
			{
				map.put("type", BDConstents.BANK_TYPE);
			}
			else if (typeTextView.equals(BDConstents.CHECK_TYPE))
			{
				map.put("type", BDConstents.CHECK_TYPE);
			}
			else if (typeTextView.equals(BDConstents.CREDIT_TYPE))
			{
				map.put("type", BDConstents.CREDIT_TYPE);
			}
			else if (typeTextView.equals(BDConstents.INOUT_TYPE))
			{
				map.put("type", BDConstents.INOUT_TYPE);
			}
		}
		else
		{
			if (typeTextView.getText().toString().equals(BDConstents.REAL_MONEY))
			{
				map.put("type", BDConstents.REAL_TYPE);
			}
			else if (typeTextView.getText().toString().equals(BDConstents.BANK_MONEY))
			{
				map.put("type", BDConstents.BANK_TYPE);
			}
			else if (typeTextView.getText().toString().equals(BDConstents.CHECK_TYPE))
			{
				map.put("type", BDConstents.CHECK_TYPE);
			}
			else if (typeTextView.getText().toString().equals(BDConstents.CREDIT_TYPE))
			{
				map.put("type", BDConstents.CREDIT_TYPE);
			}
			else if (typeTextView.getText().toString().equals(BDConstents.INOUT_TYPE))
			{
				map.put("type", BDConstents.INOUT_TYPE);
			}
		}
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		super.onActivityResult(requestCode, resultCode, data);
		
		if (requestCode == REQUEST_CATEGORY)
		{
			if (resultCode == Activity.RESULT_OK)
			{
				categoryTextView.setText(data.getStringExtra(RadioDialogActivity.RADIOSTRING));
			}
		}
		else if (requestCode == REQUEST_NAME)
		{
			if (resultCode == Activity.RESULT_OK)
			{
				nameTextView.setText(data.getStringExtra(RadioDialogActivity.RADIOSTRING));
			}
		}
		else if (requestCode == REQUEST_TYPE)
		{
			if (resultCode == Activity.RESULT_OK)
			{
				String typeName = data.getStringExtra(RadioDialogActivity.RADIOSTRING);
				
				typeTextView.setText(typeName);
				
				if (typeName.equals(BDConstents.REAL_MONEY))
				{
					setName(BDConstents.REAL_TYPE);
				}
				else if (typeName.equals(BDConstents.BANK_MONEY))
				{
					setName(BDConstents.BANK_TYPE);
				}
				else if (typeName.equals(BDConstents.CHECK_CARD))
				{
					setName(BDConstents.CHECK_TYPE);
				}
				else if (typeName.equals(BDConstents.CREDIT_CARD))
				{
					setName(BDConstents.CREDIT_TYPE);
				}
			}
		}
		else if (requestCode == REQUEST_KIND)
		{
			if (resultCode == Activity.RESULT_OK)
			{
				String typeName = data.getStringExtra(RadioDialogActivity.RADIOSTRING);
				
				kindTextView.setText(typeName);
				
				if (typeName.equals(BDConstents.REAL_MONEY))
				{
					setName(BDConstents.REAL_TYPE);
				}
				else if (typeName.equals(BDConstents.BANK_MONEY))
				{
					setName(BDConstents.BANK_TYPE);
				}
				else if (typeName.equals(BDConstents.CHECK_CARD))
				{
					setName(BDConstents.CHECK_TYPE);
				}
				else if (typeName.equals(BDConstents.CREDIT_CARD))
				{
					setName(BDConstents.CREDIT_TYPE);
				}
			}
		}
	}
	
	/**
	 * 다이얼로그 뛰우기 
	 */
	private class ShowDialog extends AsyncTask<Integer, Integer, Integer>{
		ProgressDialog dialog = null;
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			dialog = new ProgressDialog(SelectUpdateActivity.this);
			dialog.setCancelable(false);
			dialog.setMessage("Loading...");
			dialog.show();
		}
		
		@Override
		protected Integer doInBackground(Integer... arg0) {
			
			if (arg0[0] == 0)
			{
				try
				{
					sql.beginTansaction(superContext);
					
					setUpdateData();
					
					sql.setTransactionSuccessful();
				} catch (Exception e)
				{
					e.printStackTrace();
				} finally {
					try 
					{
						sql.endTransaction(superContext);
					} catch (Exception e) 
					{
						return -1;
					}
				}
				
				return 0;
			}
			
			return null;
		}
		
		@Override
		protected void onPostExecute(Integer result) {
			super.onPostExecute(result);
			
			dialog.dismiss();
			
			if (result == -1)
			{
				BDUtil.btnEnable = true;
				BDUtil.asyncFlag = 0;
				
				BDUtil.showDialog(superContext, "오류", "데이터 저장에 실패했습니다.");
			}
			else if (result == 0)
			{
				setResult(Activity.RESULT_OK);
				BDUtil.showDialogFinish(SelectUpdateActivity.this, "확인", "데이터가 수정 되었습니다.");
			}
		}
	}

	@Override
	protected void tipButton()
	{
//		Intent intent = new Intent(this, TipInfoActivity.class);
//		intent.putExtra(TipsActivity.TIP_REQUEST_KEY, TipsActivity.TIP_UPDATE);
//		startActivity(intent);
	}
}
